{include file="public/header" /}
<body class="bgc">
<div class="header">
    <i class="layui-icon layui-icon-left" onclick="goBack()"></i> 支付订单
</div>
<div class="pay-news flex-center">
    <p>实付金额</p>
    <div>￥<span>{$info.real_amount}</span></div>
</div>
<form action="{:url('order/confirmPayment')}" method="post" class="form">
    <input type="hidden" name="id" value="{$info.id}">
    <ul class="pay-list">
        {foreach name="method" key="key" item="vo"}
        <li>
            <label for="check{$key}">
                <p class="flex-center">
                    <img src="{$vo.icon}" alt="">
                </p>
                <p class="center">{$vo.title}</p>
                <img src="/static/index/img/{if $key == 0}icon7.png{else}icon6.png{/if}" alt="" class="check">
            </label>
            <input type="radio" hidden id="check{$key}" name="pay_way" value="{$vo.pay_way}" {if $key == 0}checked{/if}>
        </li>
        {/foreach}
    </ul>
    <p class="save save-fixed">确认支付</p>
    <div class="model">
        <div class="pay-mdl">
            <p class="flex-center cancel">
                <img src="/static/index/img/icon54.png" alt="">
            </p>
            <div class="pay-mdl-news">
                <div>请输入支付密码</div>
                <p class="price">￥<span>{$info.real_amount}</span></p>
                <p>实付金额</p>
                <input type="password" name="pay_password" id="pay_password" lay-verify="required" lay-reqtext="请输入支付密码" placeholder="请输入支付密码">
                <button class="btn payment" lay-submit lay-filter="save" formObj=".form">确认支付</button>
            </div>
        </div>
    </div>
</form>
</body>
{include file="public/footer" /}
<script src="/static/index/js/order.js"></script>
<script>
    $(function () {
        $(".pay-list input").click(function() {
            $(this).siblings('label').find('.check').attr('src', '/static/index/img/icon7.png');
            $(this).parent().siblings().find('.check').attr('src', '/static/index/img/icon6.png');
        });
        var os = true;
        $(".save-fixed").click(function() {
            var pay_way = $("input[name='pay_way']:checked").val();
            if (!pay_way) {
                layer.msg('请选择支付方式');
                return false;
            }
            if (pay_way === 'wechat' || pay_way === 'alipay') {
                submitObj();
            } else {
                $('.model').show();
            }
        });
        $('.cancel').click(function() {
            $('.model').hide()
        });
        $(".payment").click(function () {
            submitObj();
        });
        function submitObj() {
            if (os !== true) return false;
            $('.payment').attr('disabled', true);
            os = false;
            layer.load();
            formObj = $('.form');
            $.ajax({
                type: 'POST',
                url: formObj.attr('action'),
                data: formObj.serialize(),
                dataType: "json",
                success: function (data) {
                    layer.closeAll();
                    if(data.code < 1){
                        os = true;
                        layer.msg(data.msg);
                        $('.payment').removeAttr('disabled');
                        return false;
                    }
                    payment(data);
                    return false;
                },
                error() {
                    layer.closeAll();
                    $('.payment').removeAttr('disabled');
                }
            });
            return false;
        }
    });
</script>
</html>